---
title: Implement StreamFunction in Go
---

import { Steps, Callout } from 'nextra-theme-docs'

# Implement StreamFunction in [Golang](https://go.dev/)

<Callout emoji="🚧" type="warning">
This feature is currently in alpha and subject to change.
</Callout>

<Steps>
### Install CLI

```bash
$ curl -fsSL "https://get.yomo.run" | sh
```

[Install TinyGo](https://tinygo.org/getting-started/install/)

on Mac:

```bash
$ brew tap tinygo-org/tools
$ brew install tinygo
```

### Write a StreamFunction in Go

```go
package main

import (
	"fmt"
	"strings"

	"github.com/yomorun/yomo/serverless"
	"github.com/yomorun/yomo/serverless/guest"
)

func main() {
	guest.DataTags = DataTags
	guest.Handler = Handler
	guest.Init = Init
}

// Init will initialize the stream function
func Init() error {
	fmt.Println("wasm go sfn init")
	return nil
}

func Handler(ctx serverless.Context) {
	// load input data
	tag := ctx.Tag()
	input := ctx.Data()
	fmt.Printf("wasm go sfn received %d bytes with tag[%#x]\n", len(input), tag)

	// process app data
	output := strings.ToUpper(string(input))

	// write result to zipper
	ctx.Write(0x34, []byte(output))
}

func DataTags() []uint32 {
	return []uint32{0x33}
}
```

### Compile to [WASI](https://wasi.dev/)

```bash
$ tinygo build -o sfn.wasm -no-debug -target wasi
```

### Run Streaming Serverless Function

```bash
yomo run /path/to/sfn.wasm
```
</Steps>
